<?php

class class_mysql{
	
  var $host = "";
  var $user = "";
  var $pass = "";
  var $dbase = "";   
  var $queryid = "";
  var $selectid = "";  
  var $updateid = "";
  var $insertid = "";  
  var $result = array();  
  var $TRAIL = array(); 
    
  function class_mysql() {
	  global $CONFIG;
	  $this->host  = $CONFIG['mysql']['host'];
	  $this->user  = $CONFIG['mysql']['user'];
	  $this->pass  = $CONFIG['mysql']['pass'];
	  $this->dbase = $CONFIG['mysql']['dbase'];
	  return true;
	}
  function db_con(){
    $db = mysql_connect($this->host, $this->user, $this->pass)
    or die ("verbindung  $this->user@$this->host fehlgeschlagen");
    mysql_select_db($this->dbase, $db)
    or die ("verbindung zur datenbank $this->dbase fehlgeschlagen");
    return $db;             
  }  
  function query($sql){    
    if($this->queryid = mysql_query($sql,$this->db_con())){
     return TRUE;
    }else{
     echo $this->getError("Der mySQL Query ist fehlerhaft.");     
    }     
  }  
  function select($sql){    
    if($this->selectid = mysql_query($sql,$this->db_con())){
     return TRUE;
    }else{  
     echo $this->getError("Der mySQL Query ist fehlerhaft.");     
    }     
  }
  function insert($sql){    
    if($this->insertid = mysql_query($sql,$this->db_con())){
     return TRUE;
    }else{
     echo $this->getError("Der mySQL Query ist fehlerhaft.");     
    }     
  }  
  function update($sql){    
    if($this->updateid = mysql_query($sql,$this->db_con())){
     return TRUE;
    }else{
     echo $this->getError("Der mySQL Query ist fehlerhaft.");     
    }     
  }  

  function getRecords(){
    return @mysql_num_rows($this->selectid);
  }
    
  function getLastInsertID(){
    return mysql_insert_id();
  }
  
  function dataSeek($pos){
    return mysql_data_seek($this->selectid,$pos);
  }
  
  function fetchArray(){
    $this->result = @mysql_fetch_array($this->selectid);
    return $this->result;    
  }
  
  function fetchRow(){
    $this->result = @mysql_fetch_row($this->selectid);
    return $this->result;    
  }	

  function emptyResult(){
    return mysql_fetch_row($this->selectid);
  }
	  
  function getError($msg){
    return "<p class=\"klein\">Es ist ein Fehler aufgetreten!<br/>".$msg."<br />MySQL Fehler: ".mysql_error()."<br />
    <a href=\"JavaScript:history.back()\">zur&uuml;ck</a><br>";
  }


  function get_parentsint($katid="") {
	if(empty($katid)) { return false; }
	unset($this->TRAIL);
	$this->TRAIL = array();
	$this->get_parents($katid);
  }
 
  function get_parents($katid="") {
    if((empty($katid)) or ("$katid" == "0")) { return false;}
	$this->select("SELECT siteid,parentid,name FROM sites WHERE siteid = $katid order by softorder");
	$count = $this->getRecords(); 
    if ($count == 0) {  return false; }
    while ( $row = $this->fetchArray() ) {
	    $trail = $this->TRAIL;
	    $count = count($trail);
	    $trail[$count] = $row;
	    $this->TRAIL = $trail;
	    $id = $row["parentid"];
	    $this->get_parents($id);
    }
    return true;
  }
  
  function getkats($katparent=""){
	if(empty($katparent)) { $katparent = " = '1'"; } else { $katparent = "= $katparent"; }
	$this->select("SELECT siteid,name FROM sites WHERE parentid $katparent ORDER BY softorder");  
	$count 	= 0;
	$data 	= array();
	while( $row = ($this->fetchRow()) ) {
	  $data[$count] = $row;
	  $count++;
	}
	return $data; 	   
}


}

?>
